package com.wd.cloud.applet.controller.manage;

import com.wd.cloud.applet.common.Response;
import com.wd.cloud.applet.common.exception.CustomException;
import com.wd.cloud.applet.config.CustomListResultConfig;
import com.wd.cloud.applet.entity.bo.SysUserRoleInfoBO.SysUserRoleInfoListBO;
import com.wd.cloud.applet.entity.bo.SysUserRoleInfoBO.SysUserRoleInfoSaveBO;
import com.wd.cloud.applet.entity.commons.RequestPrimaryKeyModel;
import com.wd.cloud.applet.entity.vo.SysUserRoleInfoVO.SysUserRoleInfoListVO;
import com.wd.cloud.applet.entity.vo.SysUserRoleInfoVO.SysUserRoleInfoKeyVO;
import com.wd.cloud.applet.service.ISysUserRoleInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 用户角色关联表控制器
 * Created on 2023年04月23日
 * @author  <a href="mailto: 987707681@qq.com">hjx</a>
 * @version 1.0
 * Copyright (c) 2023年 代码生成器
 */
@Api(tags = "用户角色关联表控制器")
@RestController
@RequestMapping("api/manage/sysUserRoleInfo")
public class SysUserRoleInfoController {
    @Resource
    private ISysUserRoleInfoService sysUserRoleInfoService;

    /**
     * 新增/编辑
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增/编辑")
    @PostMapping("/save")
    public Response save(@RequestBody SysUserRoleInfoSaveBO dto) {
        if (sysUserRoleInfoService.save(dto) > 0) {
            return Response.ok();
        } else {
            throw new CustomException("操作失败", 101);
        }
    }

    /**
     * 删除操作
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "删除操作")
    @PostMapping("/delByIdentify")
    public Response delByIdentify(@RequestBody RequestPrimaryKeyModel dto) {
        if (sysUserRoleInfoService.deleteByPrimaryKey(dto) > 0) {
            return Response.ok("删除成功");
        } else {
            throw new CustomException("操作失败", 101);
        }
    }

    /**
     * 获取分页列表数据
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "获取分页列表数据")
    @PostMapping("/getUserRoleList")
    public Response<List<SysUserRoleInfoListVO>> getList(
        @RequestBody SysUserRoleInfoListBO params) {
        List<SysUserRoleInfoListVO> selectByPageList =
            sysUserRoleInfoService.selectByList(params);
        return Response.ok(selectByPageList);
    }

    /**
     * 根据ID获取实体数据
     *
     * @param dto
     * @return
     */
    @ApiOperation(value = "根据ID获取实体数据")
    @PostMapping("/getEntityByKey")
    public Response<SysUserRoleInfoKeyVO> getEntityByKey(@RequestBody RequestPrimaryKeyModel dto) {
        SysUserRoleInfoKeyVO model = sysUserRoleInfoService.selectByPrimaryKey(dto);
        return Response.ok(model);
    }
}
